package com.xxgc.vfc.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xxgc.vfc.auth.entity.Users;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户 Mapper 接口
 * </p>
 *
 * @author 风清扬
 * @since 2023-11-10
 */
public interface UsersMapper extends BaseMapper<Users> {
    //通过id查询出角色信息
    @Select("select vr.role\n" +
            "from vfc_users as vu,\n" +
            "vfc_user_and_roles as vuar,\n" +
            "vfc_roles as vr\n" +
            "WHERE\n" +
            "vu.id = vuar.user_id\n" +
            "AND\n" +
            "vuar.roles_id = vr.id\n" +
            "AND\n" +
            "vu.id = #{id}")
    List<String> getRoleList(String id);

    //通过id查询出权限信息
    @Select("SELECT \n" +
            "vp.perme\n" +
            "FROM\n" +
            "vfc_users as vu,\n" +
            "vfc_user_and_roles as vuar,\n" +
            "vfc_roles as vr,\n" +
            "vfc_role_and_perm as vrap,\n" +
            "vfc_permissions as vp\n" +
            "WHERE\n" +
            "vu.id = vuar.user_id\n" +
            "AND\n" +
            "vuar.roles_id = vr.id\n" +
            "AND\n" +
            "vr.id = vrap.r_id\n" +
            "AND\n" +
            "vrap.p_id = vp.id\n" +
            "AND\n" +
            "vu.id = #{id}\n" +
            "GROUP BY vp.perme")
    List<String> getPermissionList(String id);
}
